From 97a2f2717098561d01936e7af1ffedfd875410bf Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 9 Mar 2015 11:30:37 -0700 Subject: [PATCH] Update to rust master --- src/cargo/core/package_id_spec.rs | 3 ++- src/cargo/lib.rs | 4 ++-- src/cargo/ops/cargo_clean.rs | 5 +++-- src/cargo/ops/cargo_doc.rs | 4 ++-- src/cargo/ops/cargo_new.rs | 2 +- src/cargo/ops/cargo_package.rs | 6 +++--- src/cargo/ops/cargo_read_manifest.rs | 12 ++++++++---- src/cargo/ops/cargo_rustc/custom_build.rs | 2 +- src/cargo/ops/cargo_rustc/fingerprint.rs | 6 +++--- src/cargo/ops/cargo_rustc/layout.rs | 5 ++--- src/cargo/ops/cargo_rustc/mod.rs | 19 +++++++++---------- src/cargo/ops/cargo_test.rs | 6 +++--- src/cargo/ops/registry.rs | 4 ++-- src/cargo/sources/git/utils.rs | 4 ++-- src/cargo/sources/path.rs | 10 ++++++---- src/cargo/sources/registry.rs | 4 ++-- src/cargo/util/config.rs | 4 ++-- src/cargo/util/important_paths.rs | 6 +++--- src/cargo/util/toml.rs | 4 ++-- src/registry/lib.rs | 18 ++++++++++++------ src/rustversion.txt | 2 +- 21 files changed, 71 insertions(+), 59 deletions(-) diff --git a/src/cargo/core/package_id_spec.rs b/src/cargo/core/package_id_spec.rs index 087d996d0..e65c59980 100644 --- a/src/cargo/core/package_id_spec.rs +++ b/src/cargo/core/package_id_spec.rs @@ -77,7 +77,8 @@ impl PackageIdSpec { (name_or_version.to_string(), Some(version)) } None => { - if name_or_version.char_at(0).is_alphabetic() { + if name_or_version.chars().next().unwrap() + .is_alphabetic() { (name_or_version.to_string(), None) } else { let version = try!(name_or_version.to_semver() diff --git a/src/cargo/lib.rs b/src/cargo/lib.rs index e90594d9e..a09b47adf 100644 --- a/src/cargo/lib.rs +++ b/src/cargo/lib.rs @@ -1,6 +1,6 @@ #![deny(unused)] -#![feature(collections, hash, os, std_misc, unicode, core)] -#![feature(io, path, str_words, fs, old_io, exit_status)] +#![feature(hash, os, std_misc, unicode, core)] +#![feature(io, path, str_words, old_io, exit_status, fs_time)] #![cfg_attr(test, deny(warnings))] #[cfg(test)] extern crate hamcrest; diff --git a/src/cargo/ops/cargo_clean.rs b/src/cargo/ops/cargo_clean.rs index bbfab64c7..b9834526a 100644 --- a/src/cargo/ops/cargo_clean.rs +++ b/src/cargo/ops/cargo_clean.rs @@ -68,11 +68,12 @@ pub fn clean(manifest_path: &Path, opts: &CleanOptions) -> CargoResult<()> { } fn rm_rf(path: &Path) -> CargoResult<()> { - if path.is_dir() { + let m = fs::metadata(path); + if m.as_ref().map(|s| s.is_dir()) == Ok(true) { try!(fs::remove_dir_all(path).chain_error(|| { human("could not remove build directory") })); - } else if path.exists() { + } else if m.is_ok() { try!(fs::remove_file(path).chain_error(|| { human("failed to remove build artifact") })); diff --git a/src/cargo/ops/cargo_doc.rs b/src/cargo/ops/cargo_doc.rs index fd7304caf..94da98eef 100644 --- a/src/cargo/ops/cargo_doc.rs +++ b/src/cargo/ops/cargo_doc.rs @@ -1,5 +1,5 @@ use std::collections::HashSet; -use std::io::prelude::*; +use std::fs; use std::path::Path; use std::process::Command; @@ -57,7 +57,7 @@ pub fn doc(manifest_path: &Path, let path = package.absolute_target_dir().join("doc").join(&name) .join("index.html"); - if path.exists() { + if fs::metadata(&path).is_ok() { open_docs(&path); } } diff --git a/src/cargo/ops/cargo_new.rs b/src/cargo/ops/cargo_new.rs index 5038495bc..efb7d99e4 100644 --- a/src/cargo/ops/cargo_new.rs +++ b/src/cargo/ops/cargo_new.rs @@ -42,7 +42,7 @@ struct CargoNewConfig { pub fn new(opts: NewOptions, config: &Config) -> CargoResult<()> { let path = config.cwd().join(opts.path); - if path.exists() { + if fs::metadata(&path).is_ok() { return Err(human(format!("Destination `{}` already exists", path.display()))) } diff --git a/src/cargo/ops/cargo_package.rs b/src/cargo/ops/cargo_package.rs index 6bf4a931a..f3364737a 100644 --- a/src/cargo/ops/cargo_package.rs +++ b/src/cargo/ops/cargo_package.rs @@ -50,7 +50,7 @@ pub fn package(manifest_path: &Path, let filename = format!("package/{}-{}.crate", pkg.name(), pkg.version()); let dst = pkg.absolute_target_dir().join(&filename); - if dst.exists() { return Ok(Some(dst)) } + if fs::metadata(&dst).is_ok() { return Ok(Some(dst)) } let mut bomb = Bomb { path: Some(dst.clone()) }; @@ -104,7 +104,7 @@ fn check_metadata(pkg: &Package, config: &Config) -> CargoResult<()> { fn tar(pkg: &Package, src: &PathSource, config: &Config, dst: &Path) -> CargoResult<()> { - if dst.exists() { + if fs::metadata(&dst).is_ok() { return Err(human(format!("destination already exists: {}", dst.display()))) } @@ -149,7 +149,7 @@ fn run_verify(config: &Config, pkg: &Package, tar: &Path) let f = try!(GzDecoder::new(try!(File::open(tar)))); let dst = pkg.root().join(&format!("target/package/{}-{}", pkg.name(), pkg.version())); - if dst.exists() { + if fs::metadata(&dst).is_ok() { try!(fs::remove_dir_all(&dst)); } let mut archive = Archive::new(f); diff --git a/src/cargo/ops/cargo_read_manifest.rs b/src/cargo/ops/cargo_read_manifest.rs index 79de52a5e..39c7f9edd 100644 --- a/src/cargo/ops/cargo_read_manifest.rs +++ b/src/cargo/ops/cargo_read_manifest.rs @@ -46,11 +46,13 @@ pub fn read_packages(path: &Path, source_id: &SourceId, config: &Config) // Don't recurse into git databases if dir.file_name().and_then(|s| s.to_str()) == Some(".git") { - return Ok(false); + return Ok(false) } // Don't automatically discover packages across git submodules - if dir != path && dir.join(".git").exists() { return Ok(false); } + if dir != path && fs::metadata(&dir.join(".git")).is_ok() { + return Ok(false) + } // Don't ever look at target directories if dir.file_name().and_then(|s| s.to_str()) == Some("target") && @@ -75,11 +77,13 @@ pub fn read_packages(path: &Path, source_id: &SourceId, config: &Config) fn walk(path: &Path, callback: &mut F) -> CargoResult<()> where F: FnMut(&Path) -> CargoResult { - if !path.is_dir() { return Ok(()) } + if fs::metadata(&path).map(|m| m.is_dir()) != Ok(true) { + return Ok(()) + } if !try!(callback(path)) { trace!("not processing {}", path.display()); - return Ok(()); + return Ok(()) } // Ignore any permission denied errors because temporary directories diff --git a/src/cargo/ops/cargo_rustc/custom_build.rs b/src/cargo/ops/cargo_rustc/custom_build.rs index 628fc7b54..76ee30fb8 100644 --- a/src/cargo/ops/cargo_rustc/custom_build.rs +++ b/src/cargo/ops/cargo_rustc/custom_build.rs @@ -119,7 +119,7 @@ pub fn prepare(pkg: &Package, target: &Target, req: Platform, // // If we have an old build directory, then just move it into place, // otherwise create it! - if !build_output.exists() { + if fs::metadata(&build_output).is_err() { try!(fs::create_dir(&build_output).chain_error(|| { internal("failed to create script output directory for \ build command") diff --git a/src/cargo/ops/cargo_rustc/fingerprint.rs b/src/cargo/ops/cargo_rustc/fingerprint.rs index cc336e114..c80d26cde 100644 --- a/src/cargo/ops/cargo_rustc/fingerprint.rs +++ b/src/cargo/ops/cargo_rustc/fingerprint.rs @@ -59,7 +59,7 @@ pub fn prepare_target<'a, 'b>(cx: &mut Context<'a, 'b>, if !target.profile().is_doc() { for filename in try!(cx.target_filenames(target)).iter() { let dst = root.join(filename); - missing_outputs |= !dst.exists(); + missing_outputs |= fs::metadata(&dst).is_err(); if target.profile().is_test() { cx.compilation.tests.push((target.name().to_string(), dst)); @@ -255,13 +255,13 @@ pub fn prepare_init(cx: &mut Context, pkg: &Package, kind: Kind) let new2 = new1.clone(); let work1 = Work::new(move |_| { - if !new1.exists() { + if fs::metadata(&new1).is_err() { try!(fs::create_dir(&new1)); } Ok(()) }); let work2 = Work::new(move |_| { - if !new2.exists() { + if fs::metadata(&new2).is_err() { try!(fs::create_dir(&new2)); } Ok(()) diff --git a/src/cargo/ops/cargo_rustc/layout.rs b/src/cargo/ops/cargo_rustc/layout.rs index 14591df5c..1f6b2e50e 100644 --- a/src/cargo/ops/cargo_rustc/layout.rs +++ b/src/cargo/ops/cargo_rustc/layout.rs @@ -46,7 +46,6 @@ //! ``` use std::fs; -use std::io::prelude::*; use std::io; use std::path::{PathBuf, Path}; @@ -90,7 +89,7 @@ impl Layout { } pub fn prepare(&mut self) -> io::Result<()> { - if !self.root.exists() { + if fs::metadata(&self.root).is_err() { try!(fs::create_dir_all(&self.root)); } @@ -103,7 +102,7 @@ impl Layout { return Ok(()); fn mkdir(dir: &Path) -> io::Result<()> { - if !dir.exists() { + if fs::metadata(&dir).is_err() { try!(fs::create_dir(dir)); } Ok(()) diff --git a/src/cargo/ops/cargo_rustc/mod.rs b/src/cargo/ops/cargo_rustc/mod.rs index 7553bc46d..397e758b0 100644 --- a/src/cargo/ops/cargo_rustc/mod.rs +++ b/src/cargo/ops/cargo_rustc/mod.rs @@ -1,7 +1,7 @@ use std::collections::{HashSet, HashMap}; use std::dynamic_lib::DynamicLibrary; use std::env; -use std::ffi::{OsStr, AsOsStr, OsString}; +use std::ffi::OsString; use std::fs; use std::io::prelude::*; use std::path::{self, PathBuf}; @@ -368,7 +368,7 @@ fn rustc(package: &Package, target: &Target, // this manually for filename in filenames.iter() { let dst = root.join(filename); - if dst.exists() { + if fs::metadata(&dst).is_ok() { try!(fs::remove_file(&dst)); } } @@ -662,12 +662,12 @@ fn build_deps_args(cmd: &mut CommandPrototype, target: &Target, let layout = cx.layout(package, kind); cmd.arg("-L").arg(&{ let mut root = OsString::from_str("dependency="); - root.push_os_str(layout.root().as_os_str()); + root.push(layout.root()); root }); cmd.arg("-L").arg(&{ let mut deps = OsString::from_str("dependency="); - deps.push_os_str(layout.deps().as_os_str()); + deps.push(layout.deps()); deps }); @@ -695,12 +695,11 @@ fn build_deps_args(cmd: &mut CommandPrototype, target: &Target, for filename in try!(cx.target_filenames(target)).iter() { if filename.ends_with(".a") { continue } let mut v = OsString::new(); - v.push_os_str(OsStr::from_str(target.name())); - v.push_os_str(OsStr::from_str("=")); - v.push_os_str(layout.root().as_os_str()); - let s = path::MAIN_SEPARATOR.to_string(); - v.push_os_str(OsStr::from_str(&s)); - v.push_os_str(OsStr::from_str(&filename)); + v.push(target.name()); + v.push("="); + v.push(layout.root()); + v.push(&path::MAIN_SEPARATOR.to_string()); + v.push(&filename); cmd.arg("--extern").arg(&v); } Ok(()) diff --git a/src/cargo/ops/cargo_test.rs b/src/cargo/ops/cargo_test.rs index d4faec1d8..05469bf4e 100644 --- a/src/cargo/ops/cargo_test.rs +++ b/src/cargo/ops/cargo_test.rs @@ -1,4 +1,4 @@ -use std::ffi::{OsStr, OsString, AsOsStr}; +use std::ffi::OsString; use std::path::Path; use core::Source; @@ -80,8 +80,8 @@ pub fn run_tests(manifest_path: &Path, for (pkg, libs) in compile.libraries.iter() { for lib in libs.iter() { let mut arg = OsString::from_str(pkg.name()); - arg.push_os_str(OsStr::from_str("=")); - arg.push_os_str(lib.as_os_str()); + arg.push("="); + arg.push(lib); p.arg("--extern").arg(&arg); } } diff --git a/src/cargo/ops/registry.rs b/src/cargo/ops/registry.rs index 8e8adfba1..fbf3ea92d 100644 --- a/src/cargo/ops/registry.rs +++ b/src/cargo/ops/registry.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; use std::env; -use std::fs::File; +use std::fs::{self, File}; use std::io::prelude::*; use std::iter::repeat; use std::path::{Path, PathBuf}; @@ -109,7 +109,7 @@ fn transmit(pkg: &Package, tarball: &Path, registry: &mut Registry) }; match *license_file { Some(ref file) => { - if !pkg.root().join(file).exists() { + if fs::metadata(&pkg.root().join(file)).is_err() { return Err(human(format!("the license file `{}` does not exist", file))) } diff --git a/src/cargo/sources/git/utils.rs b/src/cargo/sources/git/utils.rs index d467cbe21..a49d500de 100644 --- a/src/cargo/sources/git/utils.rs +++ b/src/cargo/sources/git/utils.rs @@ -150,7 +150,7 @@ impl GitRemote { fn clone_into(&self, dst: &Path) -> CargoResult { let url = self.url.to_string(); - if dst.exists() { + if fs::metadata(&dst).is_ok() { try!(fs::remove_dir_all(dst)); } try!(fs::create_dir_all(dst)); @@ -252,7 +252,7 @@ impl<'a> GitCheckout<'a> { human(format!("Couldn't mkdir {}", dirname.display())) })); - if into.exists() { + if fs::metadata(&into).is_ok() { try!(fs::remove_dir_all(into).chain_error(|| { human(format!("Couldn't rmdir {}", into.display())) })); diff --git a/src/cargo/sources/path.rs b/src/cargo/sources/path.rs index b64f4c151..6e56f9941 100644 --- a/src/cargo/sources/path.rs +++ b/src/cargo/sources/path.rs @@ -167,7 +167,7 @@ impl<'a, 'b> PathSource<'a, 'b> { // TODO: the `entry` has a mode we should be able to look at instead // of just calling stat() again - if file_path.is_dir() { + if fs::metadata(&file_path).map(|m| m.is_dir()) == Ok(true) { warn!(" found submodule {}", file_path.display()); let rel = file_path.relative_from(&root).unwrap(); let rel = try!(rel.to_str().chain_error(|| { @@ -223,14 +223,16 @@ impl<'a, 'b> PathSource<'a, 'b> { is_root: bool, filter: &mut F) -> CargoResult<()> where F: FnMut(&Path) -> bool { - if !path.is_dir() { + if fs::metadata(&path).map(|m| m.is_dir()) != Ok(true) { if (*filter)(path) { ret.push(path.to_path_buf()); } return Ok(()) } // Don't recurse into any sub-packages that we have - if !is_root && path.join("Cargo.toml").exists() { return Ok(()) } + if !is_root && fs::metadata(&path.join("Cargo.toml")).is_ok() { + return Ok(()) + } for dir in try!(fs::read_dir(path)) { let dir = try!(dir).path(); match (is_root, dir.file_name().and_then(|s| s.to_str())) { @@ -298,7 +300,7 @@ impl<'a, 'b> Source for PathSource<'a, 'b> { // condition where this path was rm'ed - either way, // we can ignore the error and treat the path's mtime // as 0. - let mtime = file.metadata().map(|s| s.modified()).unwrap_or(0); + let mtime = fs::metadata(&file).map(|s| s.modified()).unwrap_or(0); warn!("{} {}", mtime, file.display()); max = cmp::max(max, mtime); } diff --git a/src/cargo/sources/registry.rs b/src/cargo/sources/registry.rs index c28f9f269..e4e45bd58 100644 --- a/src/cargo/sources/registry.rs +++ b/src/cargo/sources/registry.rs @@ -301,7 +301,7 @@ impl<'a, 'b> RegistrySource<'a, 'b> { // TODO: should discover from the S3 redirect let filename = format!("{}-{}.crate", pkg.name(), pkg.version()); let dst = self.cache_path.join(&filename); - if dst.exists() { return Ok(dst) } + if fs::metadata(&dst).is_ok() { return Ok(dst) } try!(self.config.shell().status("Downloading", pkg)); try!(fs::create_dir_all(dst.parent().unwrap())); @@ -347,7 +347,7 @@ impl<'a, 'b> RegistrySource<'a, 'b> { -> CargoResult { let dst = self.src_path.join(&format!("{}-{}", pkg.name(), pkg.version())); - if dst.join(".cargo-ok").exists() { return Ok(dst) } + if fs::metadata(&dst.join(".cargo-ok")).is_ok() { return Ok(dst) } try!(fs::create_dir_all(dst.parent().unwrap())); let f = try!(File::open(&tarball)); diff --git a/src/cargo/util/config.rs b/src/cargo/util/config.rs index ad8f359d3..7677da2da 100644 --- a/src/cargo/util/config.rs +++ b/src/cargo/util/config.rs @@ -393,7 +393,7 @@ fn walk_tree(pwd: &Path, mut walk: F) -> CargoResult<()> loop { let possible = current.join(".cargo").join("config"); - if possible.exists() { + if fs::metadata(&possible).is_ok() { let file = try!(File::open(&possible)); try!(walk(file, &possible)); @@ -413,7 +413,7 @@ fn walk_tree(pwd: &Path, mut walk: F) -> CargoResult<()> })); if !pwd.starts_with(&home) { let config = home.join("config"); - if config.exists() { + if fs::metadata(&config).is_ok() { let file = try!(File::open(&config)); try!(walk(file, &config)); } diff --git a/src/cargo/util/important_paths.rs b/src/cargo/util/important_paths.rs index 7facb0980..365ddabe3 100644 --- a/src/cargo/util/important_paths.rs +++ b/src/cargo/util/important_paths.rs @@ -1,5 +1,5 @@ use std::env; -use std::io::prelude::*; +use std::fs; use std::path::{Path, PathBuf}; use util::{CargoResult, human, ChainError}; @@ -20,7 +20,7 @@ pub fn find_project_manifest(pwd: &Path, file: &str) -> CargoResult { loop { let manifest = current.join(file); - if manifest.exists() { + if fs::metadata(&manifest).is_ok() { return Ok(manifest) } @@ -50,7 +50,7 @@ pub fn find_root_manifest_for_cwd(manifest_path: Option) pub fn find_project_manifest_exact(pwd: &Path, file: &str) -> CargoResult { let manifest = pwd.join(file); - if manifest.exists() { + if fs::metadata(&manifest).is_ok() { Ok(manifest) } else { Err(human(format!("Could not find `{}` in `{}`", diff --git a/src/cargo/util/toml.rs b/src/cargo/util/toml.rs index 80a80e776..35e130418 100644 --- a/src/cargo/util/toml.rs +++ b/src/cargo/util/toml.rs @@ -44,7 +44,7 @@ impl Layout { } fn try_add_file(files: &mut Vec, file: PathBuf) { - if file.exists() { + if fs::metadata(&file).is_ok() { files.push(file); } } @@ -72,7 +72,7 @@ pub fn project_layout(root_path: &Path) -> Layout { let mut benches = vec!(); let lib_canidate = root_path.join("src").join("lib.rs"); - if lib_canidate.exists() { + if fs::metadata(&lib_canidate).is_ok() { lib = Some(lib_canidate); } diff --git a/src/registry/lib.rs b/src/registry/lib.rs index d6022b127..93b94b66c 100644 --- a/src/registry/lib.rs +++ b/src/registry/lib.rs @@ -1,4 +1,4 @@ -#![feature(core, io, path, fs)] +#![feature(io, path)] extern crate curl; extern crate "rustc-serialize" as rustc_serialize; @@ -142,14 +142,14 @@ impl Registry { (json.len() >> 8) as u8, (json.len() >> 16) as u8, (json.len() >> 24) as u8, - ].iter().cloned()); - w.extend(json.as_bytes().iter().cloned()); + ].iter().map(|x| *x)); + w.extend(json.as_bytes().iter().map(|x| *x)); w.extend([ (stat.len() >> 0) as u8, (stat.len() >> 8) as u8, (stat.len() >> 16) as u8, (stat.len() >> 24) as u8, - ].iter().cloned()); + ].iter().map(|x| *x)); w }; let tarball = try!(File::open(tarball).map_err(Error::Io)); @@ -158,7 +158,10 @@ impl Registry { let url = format!("{}/api/v1/crates/new", self.host); - let token = try!(self.token.as_ref().ok_or(Error::TokenMissing)); + let token = match self.token.as_ref() { + Some(s) => s, + None => return Err(Error::TokenMissing), + }; let request = self.handle.put(url, &mut body) .content_length(size) .header("Accept", "application/json") @@ -209,7 +212,10 @@ impl Registry { .content_type("application/json"); if authorized == Auth::Authorized { - let token = try!(self.token.as_ref().ok_or(Error::TokenMissing)); + let token = match self.token.as_ref() { + Some(s) => s, + None => return Err(Error::TokenMissing), + }; req = req.header("Authorization", &token); } match body { diff --git a/src/rustversion.txt b/src/rustversion.txt index ac5240e64..427618d48 100644 --- a/src/rustversion.txt +++ b/src/rustversion.txt @@ -1 +1 @@ -2015-03-04 +2015-03-09 -- 2.30.2